
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <stdio.h>
#include <sys/time.h>
#include "app_platform/cntl_info.h"
#include "app_platform/cgi_stub_cntl.h"
#include "../include/companydao_stub4web_allinone.h"
#include <set>	
#include "erp/company/ddo/companyinfoddo_company.h"	
#include <map>	
#include "erp/company/ddo/companyfilterddo_company.h"	
#include <vector>	

using namespace erp::company::dao;

void Init()
{       
	if(CCGI_STUB_CNTL->Initialize(true) != 0)
		std::cerr << "CCGI_STUB_CNTL->Init failed" << std::endl;
	CCGI_STUB_CNTL->setTimeout(5);
}
void TestAddAndUpdateCompany()
{
	//TODO 如果使用配置中心来获取APP地址,请注释下行
	//CCGI_STUB_CNTL->setPeerAddr("172.25.34.123", 53101);

	//TODO 请设置用户Passport
	CCntlInfo oCntlInfo;
	oCntlInfo.setOperatorUin(88883687);
	oCntlInfo.setOperatorClientIP(0);
	oCntlInfo.setOperatorKey("stw3ymf9uk");
	//TODO 请设置路由值
	oCntlInfo.setRouteKey(88883687);
	std::string machineKey = "";		
	std::string source = "";		
	uint32_t sceneId = 0;
	erp::company::ddo::CCompanyInfoDdo companyInfo;
	std::string inReserve = "";		
	std::string errmsg = "";		
	std::string outReserve = "";		
	CCompanyDaoStub4Web oStub;



	std::stringstream strFCompanyName;
		strFCompanyName << "易金商测试企业DDO";
		companyInfo.SetCompanyName(strFCompanyName.str());
		std::stringstream strTableID;
		strTableID << "002";
		companyInfo.SetTableID();

		std::stringstream strCompanyCorporation;
		strCompanyCorporation << "StoneBu1";

		companyInfo.SetCompanyCorporation(strCompanyCorporation.str());
		std::stringstream strFCompanyID;
		strFCompanyID << "002";
		companyInfo.SetCompanyID(strFCompanyID.str());
		companyInfo.SetCreatorSysNo(22);
		companyInfo.SetModifierSysNo(11);



	// TODO:替换函数参数
    uint32_t dwResult = oStub.AddAndUpdateCompany(
		oCntlInfo,
		machineKey,
		source,
		sceneId,
		companyInfo,
		inReserve,
		errmsg,
		outReserve
  	);
    if(dwResult == 0)
	{
		std::cout << "Invoke OK!" << std::endl;
		printf("OK result[0x%x], time = %ld\n"
        , dwResult, oStub.GetLastConsumeTime());
	}
	else
    {
        printf("Error result[0x%x], time = %ld , errmsg = [%s]\n"
        , dwResult, oStub.GetLastConsumeTime(),oStub.GetLastErrMsg());
    }
}
void TestDeleteCompany()
{
	//TODO 如果使用配置中心来获取APP地址,请注释下行
	//CCGI_STUB_CNTL->setPeerAddr("172.25.34.123", 53101);

	//TODO 请设置用户Passport
	CCntlInfo oCntlInfo;
	oCntlInfo.setOperatorUin(88883687);
	oCntlInfo.setOperatorClientIP(0);
	oCntlInfo.setOperatorKey("stw3ymf9uk");
	//TODO 请设置路由值
	oCntlInfo.setRouteKey(88883687);
	std::string machineKey = "";		
	std::string source = "";		
	uint32_t sceneId = 0;
	erp::company::ddo::CCompanyInfoDdo companyInfo;
	std::string inReserve = "";		
	std::string errmsg = "";		
	std::string outReserve = "";		
	CCompanyDaoStub4Web oStub;
	// TODO:替换函数参数
    uint32_t dwResult = oStub.DeleteCompany(
		oCntlInfo,
		machineKey,
		source,
		sceneId,
		companyInfo,
		inReserve,
		errmsg,
		outReserve
  	);
    if(dwResult == 0)
	{
		std::cout << "Invoke OK!" << std::endl;
		printf("OK result[0x%x], time = %ld\n"
        , dwResult, oStub.GetLastConsumeTime());
	}
	else
    {
        printf("Error result[0x%x], time = %ld , errmsg = [%s]\n"
        , dwResult, oStub.GetLastConsumeTime(),oStub.GetLastErrMsg());
    }
}
void TestGetCompany()
{
	//TODO 如果使用配置中心来获取APP地址,请注释下行
	//CCGI_STUB_CNTL->setPeerAddr("172.25.34.123", 53101);

	//TODO 请设置用户Passport
	CCntlInfo oCntlInfo;
	oCntlInfo.setOperatorUin(88883687);
	oCntlInfo.setOperatorClientIP(0);
	oCntlInfo.setOperatorKey("stw3ymf9uk");
	//TODO 请设置路由值
	oCntlInfo.setRouteKey(88883687);
	std::string machineKey = "";		
	std::string source = "";		
	uint32_t sceneId = 0;
	erp::company::ddo::CCompanyFilterDdo companyFilter;
	std::string inReserve = "";		
	std::string errmsg = "";		
	std::vector<erp::company::ddo::CCompanyInfoDdo > companyInfo;
	std::string outReserve = "";		
	CCompanyDaoStub4Web oStub;
	// TODO:替换函数参数
    uint32_t dwResult = oStub.GetCompany(
		oCntlInfo,
		machineKey,
		source,
		sceneId,
		companyFilter,
		inReserve,
		errmsg,
		companyInfo,
		outReserve
  	);
    if(dwResult == 0)
	{
		std::cout << "Invoke OK!" << std::endl;
		printf("OK result[0x%x], time = %ld\n"
        , dwResult, oStub.GetLastConsumeTime());
	}
	else
    {
        printf("Error result[0x%x], time = %ld , errmsg = [%s]\n"
        , dwResult, oStub.GetLastConsumeTime(),oStub.GetLastErrMsg());
    }
}
void TestGetCompanyByIds()
{
	//TODO 如果使用配置中心来获取APP地址,请注释下行
	//CCGI_STUB_CNTL->setPeerAddr("172.25.34.123", 53101);

	//TODO 请设置用户Passport
	CCntlInfo oCntlInfo;
	oCntlInfo.setOperatorUin(88883687);
	oCntlInfo.setOperatorClientIP(0);
	oCntlInfo.setOperatorKey("stw3ymf9uk");
	//TODO 请设置路由值
	oCntlInfo.setRouteKey(88883687);
	std::string machineKey = "";		
	std::string source = "";		
	uint32_t sceneId = 0;
	std::set<uint32_t > companysysNoList;
	std::string inReserve = "";		
	std::string errmsg = "";		
	std::map<uint32_t,erp::company::ddo::CCompanyInfoDdo > companyInfo;
	std::string outReserve = "";		
	CCompanyDaoStub4Web oStub;
	// TODO:替换函数参数
    uint32_t dwResult = oStub.GetCompanyByIds(
		oCntlInfo,
		machineKey,
		source,
		sceneId,
		companysysNoList,
		inReserve,
		errmsg,
		companyInfo,
		outReserve
  	);
    if(dwResult == 0)
	{
		std::cout << "Invoke OK!" << std::endl;
		printf("OK result[0x%x], time = %ld\n"
        , dwResult, oStub.GetLastConsumeTime());
	}
	else
    {
        printf("Error result[0x%x], time = %ld , errmsg = [%s]\n"
        , dwResult, oStub.GetLastConsumeTime(),oStub.GetLastErrMsg());
    }
}
//测试主函数
int main(int argc, char** argv)
{
	//
	//测试主流程
	// 开发人员可以根据业务需要进行顺序的调整，以期达到更好的测试效果
	// 比如，可以按照插入、选择、修改、选择、删除、选择 顺序进行处理
	//
	Init();
	TestAddAndUpdateCompany();
	TestDeleteCompany();
	TestGetCompany();
	TestGetCompanyByIds();
	return 0;
}
